<?php
/**
 * Created by PhpStorm.
 * User: chriswu
 * Date: 2019/3/6
 * Time: 10:35
 */
namespace app\controllers;

use Yii;

class RegQrCodeController extends BaseController
{
    /** @var \common\logics\regqrcode\RegQrCodeLogic $RegQrCodeService */
    private $RegQrCodeService;
    /**@var \common\logics\auth\AuthLogic $AuthService */
    private $AuthService;

    public function init()
    {
        $this->AuthService = Yii::$container->get("AuthService");
        $this->RegQrCodeService = Yii::$container->get("RegQrCodeService");
        return parent::init(); // TODO: Change the autogenerated stub
    }
    /**
     * 获取注册二维码列表
     */
    public function actionRegQrCodeList(){
        $check = $this->AuthService->checkPower();
        if (true !== $check) {
            return $check;
        }
        $result = $this->RegQrCodeService->getRegQrCodeList();
        return $result;
    }

    /**
     * 修改注册二维码
     */
    public function actionUpdateRegQrCode() {
        $check = $this->AuthService->checkPower();
        if (true !== $check) {
            return $check;
        }
        $param = [
            'qrcode_id' => Yii::$app->request->post("qrcode_id",''),
            'qrcode_img' => Yii::$app->request->post("qrcode_img",'')
        ];
        $result = $this->RegQrCodeService->setRegQrCodeImg($param);
        return $result;
    }

    /**
     * 启用二维码
     */
    public function actionUseQrCode() {
        $check = $this->AuthService->checkPower();
        if (true !== $check) {
            return $check;
        }
        $param = [
            'qrcode_id' => Yii::$app->request->post("qrcode_id",''),
            'is_use' => Yii::$app->request->post("is_use",'2')//是否启用  默认2—禁用
        ];
        $result = $this->RegQrCodeService->UseQrCode($param);
        return $result;
    }

    /**
     * 删除注册二维码
     */
    public function actionDelQrCode() {
        $check = $this->AuthService->checkPower();
        if (true !== $check) {
            return $check;
        }
        $param = [
            'qrcode_id' => Yii::$app->request->post("qrcode_id",''),
        ];
        $result = $this->RegQrCodeService->DelQrCode($param);
        return $result;
    }

    /**
     * 新增注册二维码
     */
    public function actionInsQrCode() {
        $check = $this->AuthService->checkPower();
        if (true !== $check) {
            return $check;
        }
        $param = [
            'qrcode_name' => trim(Yii::$app->request->post("qrcode_name",'')),
            'qrcode_img' => trim(Yii::$app->request->post("qrcode_img",'')),
        ];
        $result = $this->RegQrCodeService->InsQrCode($param);
        return $result;
    }
}